<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/functions.php");
include("../../class/class.php");
include "../".LoadLang("pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$logininid=(int)$_GET['userid'];
$loginin=$_GET['username'];
$loginrnd=$_GET['rnd'];
$classid=(int)$_GET['classid'];
$filepass=(int)$_GET['filepass'];
$type=(int)$_GET['type'];
$doing=$_GET['doing'];
$field=$_GET['field'];
$tranfrom=$_GET['tranfrom'];
if(empty($field))
{
	$field="ecms";
}
$editor=1;
is_login($logininid,$loginin,$loginrnd);
$add="";
//栏目
$searchclassid=$_GET['searchclassid'];
if($searchclassid=='all')
{
	$searchclassid=0;
	$searchvarclassid='all';
}
else
{
	$searchclassid=$searchclassid?$searchclassid:$classid;
	$searchvarclassid=$searchclassid;
}
$searchclassid=(int)$searchclassid;
if($searchclassid)
{
	$add.=" and classid='$searchclassid'";
}
//关键字
$keyboard=RepPostVar2($_GET['keyboard']);
if(!empty($keyboard))
{
	$show=$_GET['show'];
	if($show==0)//搜索全部
	{
		$add.=" and (filename like '%$keyboard%' or no like '%$keyboard%' or adduser like '%$keyboard%')";
	}
	elseif($show==1)//搜索文件名
	{
		$add.=" and filename like '%$keyboard%'";
	}
	elseif($show==2)//搜索编号
	{
		$add.=" and no like '%$keyboard%'";
	}
	else//搜索上传者
	{
		$add.=" and adduser like '%$keyboard%'";
	}
}
$search="&userid=$logininid&username=$loginin&rnd=$loginrnd&classid=$classid&filepass=$filepass&type=$type&doing=$doing&tranfrom=$tranfrom&field=$field&show=$show&searchclassid=$searchvarclassid&keyboard=$keyboard";
//分页
$page=(int)$_GET['page'];
$start=(int)$_GET['start'];
$line=25;//每页显示条数
if($type==1)//图片
{
	$line=12;
}
$page_line=12;//每页显示链接数
$offset=$start+$page*$line;//总偏移量
$query="select fileid,filename,filesize,path,filetime,classid,no,fpath from {$dbtbpre}enewsfile where type='$type'".$add;
$totalquery="select count(*) as total from {$dbtbpre}enewsfile where type='$type'".$add;
$num=$empire->gettotal($totalquery);//取得总条数
$query.=" order by fileid desc limit $offset,$line";
$sql=$empire->query($query);
$returnpage=page1($num,$line,$page_line,$start,$page,$search);
/*
//操作的栏目
$fcjsfile='../../data/fc/cmsclass.js';
$do_class=GetFcfiletext($fcjsfile);
if($searchclassid)
{
	$do_class=str_replace("<option value='$searchclassid'","<option value='$searchclassid' selected",$do_class);
}
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>插入文件</title>
<link href="edit.css" rel="stylesheet" type="text/css">
<link href="../../data/images/css.css" rel="stylesheet" type="text/css">
<script>
function InsertFile(filename,fname,fileid,filesize,filetype,fileno,dotype){
	var vstr="";
	if(dotype!=undefined)
	{
		vstr=showModalDialog("popups/insertfile.php?ecms="+dotype+"&fname="+fname+"&fileid="+fileid+"&filesize="+filesize+"&filetype="+filetype+"&filename="+filename, "", "dialogWidth:45.5em; dialogHeight:27.5em; status:0");
		if(vstr==undefined)
		{
			return false;
		}
	}
	opener.DoFile(vstr);
	window.close();
}
function TInsertFile(vstr){
	opener.DoFile(vstr);
	window.close();
}
function ChangeFile1(obj,str)
{
	if(obj==1)
	{opener.document.add.<?=$field?>.value=str;}
	else
	{opener.document.form1.<?=$field?>.value=str;}
	window.close();
}
//编辑器选择
function EditorChangeFile(str)
{
	<?=$field?>.value=str;
	opener.document.getElementById('viewpic').src=str;
	opener.document.getElementById('viewpiclink').href=str;
	window.close();
}
//变量层选择
function SFormIdChangeFile(name,url,filesize,filetype,idvar)
{
	window.opener.doSpChangeFile(name,url,filesize,filetype,idvar);
	window.close();
}
</script>
<script>
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
</script>
<script src=ebb.js></script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr> 
    <td height="230" colspan="3"> <IFRAME frameBorder=0 id=tran name=tran scrolling=auto src=tran.php<? echo"?userid=$logininid&username=$loginin&rnd=$loginrnd&type=$type&classid=$classid&filepass=$filepass";?> style=HEIGHT:100%;VISIBILITY:inherit;WIDTH:100%;Z-INDEX:1></IFRAME> 
    </td>
  </tr>
  <tr> 
    <td width="41%">&nbsp;</td>
    <td width="21%"><div align="center"> </div></td>
    <td width="38%">&nbsp;</td>
  </tr>
</table>
<table width="99%" border="0" align="center" cellpadding="3" cellspacing="0">
  <form name="searchfile" method="get" action="file.php">
  <input type=hidden name=type value="<?=$type?>">
  <input type=hidden name=classid value="<?=$classid?>">
  <input type=hidden name=filepass value="<?=$filepass?>">
  <input type=hidden name=userid value="<?=$logininid?>">
  <input type=hidden name=username value="<?=$loginin?>">
  <input type=hidden name=rnd value="<?=$loginrnd?>">
  <input type=hidden name=doing value="<?=$doing?>">
  <input type=hidden name=tranfrom value="<?=$tranfrom?>">
  <input type=hidden name=field value="<?=$field?>">
    <tr> 
      <td><div align="center">搜索： 
          <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>">
          <select name="show" id="show">
		  <option value="0">不限</option>
		  <option value="1">文件名</option>
		  <option value="2" selected>编号</option>
		  <option value="3">上传者</option>
          </select>
		  <span id="fileclassnav"></span>
          <input type="submit" name="Submit2" value="搜索">
        </div></td>
    </tr>
  </form>
</table>
<form name="dofile" method="post" action="../enews.php?<? echo"userid=$logininid&username=$loginin&rnd=$loginrnd";?>" onsubmit="return confirm('确认要操作?');">
<input type=hidden name=enews value="DoMarkSmallPic">
  <input type=hidden name=type value="<?=$type?>">
  <input type=hidden name=classid value="<?=$classid?>">
  <input type=hidden name=searchclassid value="<?=$searchclassid?>">
  <input type=hidden name=filepass value="<?=$filepass?>">
  <input type=hidden name=doing value="<?=$doing?>">
  <input type=hidden name=field value="<?=$field?>">
<?
//图片
if($type==1)
{
	$i=0;
	$line=3;//每行显示图片数
	$width=100;
	$height=80;
	$sub=23;//编号截取数
	while($r=$empire->fetch($sql))
	{
		$ono=$r[no];
		$r[no]=sub($r[no],0,$sub,false);
		$filesize=ChTheFilesize($r[filesize]);
		//取得文件扩展名
		$filetype=GetFiletype($r[filename]);
		$i++;
		if(($i-1)%$line==0||$i==1)
		{$class_text.="<tr bgcolor='#DBEAF5'>";}
		//文件
		$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
		$filepath=$r[path]?$r[path].'/':$r[path];
		$file=$fspath['fileurl'].$filepath.$r[filename];
		$pic=$file;
		//返回地址
		if($doing==1)
		{
			$returnstr=$pic;
			$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(1,'".$pic."');\">";
		}
		elseif($doing==2)
		{
			$returnstr=$pic;
			$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(2,'".$pic."');\">";
		}
		else
		{
			//编辑器选择
			if($tranfrom==1)
			{
				$button="<input type=button name=button value='选择' onclick=\"javascript:EditorChangeFile('".$pic."');\">";
			}
			//特殊字段选择
			elseif($tranfrom==2)
			{
				$button="<input type=button name=button value='选择' onclick=\"javascript:SFormIdChangeFile('$ono','$pic','$filesize','$filetype','$field');\">";
			}
			else
			{
				$button="<input type=button name=button value='插入' onclick=\"javascript:InsertFile('$file','$r[filename]','$r[fileid]','$filesize','$filetype','','pic');\">";
			}
		}
		$viewstr="预览";
		$class_text.="<td><table width='100%' border=0 cellspacing=1 cellpadding=2>
			<tr> 
                <td width='28%' valign=top>图片:<br><input type=checkbox name=fileid[] value='$r[fileid]'></td>
                <td width='72%'><a href='../../ViewImg/index.html?url=".$file."' target='_blank' title='预览:".$r[filename]."'><img src='".$pic."' width='".$width."' height='".$height."' border=0></a></td>
            </tr>
            <tr> 
                <td>编号:</td>
                <td><a title='".$ono."'>".$r[no]."</a></td>
			</tr> 
            <tr> 
				<td>文件大小:</td>
				<td>".$filesize."</td>
            </tr>
            <tr> 
				<td>所属栏目:</td>
                <td>".$class_r[$r[classid]][classname]."</td>
             </tr>
             <tr> 
                <td colspan=2><div align=center>".$button."</div></td>
             </tr>
            </table></td>";
		//分割
		if($i%$line==0)
		{$class_text.="</tr>";}
	}
	if($i<>0)
	{
		$table="<table width='100%' border=0 cellpadding=3 cellspacing=1 bgcolor='#698CC3'>
				<tr>
					<td><strong><font color='#FFFFFF'>插入/选择图片</font></strong></td>
				</tr>
				<tr>
					<td bgcolor='#FFFFFF'><table width='100%' border=1 align=center cellpadding=2 cellspacing=1 bordercolor='#FFFFFF' bgcolor='#FFFFFF'>";
		$table1="</table></td>
				</tr>
				<tr>
					<td bgcolor='#FFFFFF'>
					&nbsp;&nbsp;".$returnpage."
					</td>
				</tr></table>";
		$ys=$line-$i%$line;
		$p=0;
		for($j=0;$j<$ys&&$ys!=$line;$j++)
		{
			$p=1;
			$class_text.="<td>&nbsp;</td>";
		}
		if($p==1)
		{
			$class_text.="</tr>";
		}
	}
	$text=$table.$class_text.$table1;
	echo"$text";
?>
  <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
      <td height="25">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="getmark" type="checkbox" id="getmark" value="1">
        <a href="../SetEnews.php" target="_blank">加水印</a>,
        <input name="getsmall" type="checkbox" id="getsmall" value="1">
        生成缩略图:缩图宽度: 
        <input name="width" type="text" id="width" value="105" size="6">
        * 高度: 
        <input name="height" type="text" id="height" value="118" size="6">
        <input type="submit" name="Submit" value="操作选中图片">
        &nbsp;&nbsp;<input type="submit" name="Submit3" value="删除选中" onclick="document.dofile.enews.value='TDelFile_all';"><input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)">全选 </td>
    </tr>
  </table>
<?
}
//flash
elseif($type==2)
{
?>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr>
    <td height="25">插入FLASH：</td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#698CC3">
  <tr> 
    <td width="7%"><div align="center"><font color="#FFFFFF">ID</font></div></td>
    <td width="43%"><div align="center"><font color="#FFFFFF">文件名</font></div></td>
    <td width="18%"><div align="center"><font color="#FFFFFF">大小</font></div></td>
    <td width="22%"><div align="center"><font color="#FFFFFF">上传时间</font></div></td>
    <td width="10%"><div align="center"><font color="#FFFFFF">选择</font></div></td>
  </tr>
  <?
  while($r=$empire->fetch($sql))
  {
	$filesize=ChTheFilesize($r[filesize]);
	//文件
	$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
	$filepath=$r[path]?$r[path].'/':$r[path];
	$file=$fspath['fileurl'].$filepath.$r[filename];
	//取得文件类型
	$filetype=substr(GetFiletype($r[filename]),1);
	//---------返回地址
	$pic=$file;
	if($doing==1)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(1,'".$pic."');\">";
	}
	elseif($doing==2)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(2,'".$pic."');\">";
	}
	else
	{
		//编辑器选择
		if($tranfrom==1)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:EditorChangeFile('".$pic."');\">";
		}
		//特殊字段选择
		elseif($tranfrom==2)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:SFormIdChangeFile('$r[no]','$pic','$filesize','$filetype','$field');\">";
		}
		else
		{
			$button="<input type=button name=button value='插入' onclick=\"javascript:InsertFile('$file','$r[filename]','$r[fileid]','$filesize','$filetype','','flash');\">";
		}
	}
?>
  <tr> 
    <td bgcolor="#FFFFFF"> <div align="center">
	<input type=checkbox name=fileid[] value="<?=$r[fileid]?>"><br>
        <?=$r[fileid]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td>
              <?=$r[no]?>
            </td>
          </tr>
          <tr> 
            <td>
              <a href='<?=$pic?>' target=_blank><?=$r[filename]?></a>
              </td>
          </tr>
        </table>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$filesize?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$r[filetime]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <?=$button?>
      </div></td>
  </tr>
  <?
  }
  ?>
  <tr> 
    <td colspan="5" bgcolor="#FFFFFF">&nbsp;&nbsp;<?=$returnpage?>
        &nbsp;&nbsp;<input type="submit" name="Submit32" value="删除选中" onclick="document.dofile.enews.value='TDelFile_all';"><input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)">全选</td>
  </tr>
</table>
<?
}
//多媒体文件
elseif($type==3)
{
	$width="[!--rm.width--]";//宽度
	$height="[!--rm.height--]";//高度
?>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr>
    <td height="25">插入多媒体文件：</td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#698CC3">
  <tr> 
    <td width="7%"><div align="center"><font color="#FFFFFF">ID</font></div></td>
    <td width="43%"><div align="center"><font color="#FFFFFF">文件名</font></div></td>
    <td width="18%"><div align="center"><font color="#FFFFFF">大小</font></div></td>
    <td width="22%"><div align="center"><font color="#FFFFFF">上传时间</font></div></td>
    <td width="10%"><div align="center"><font color="#FFFFFF">选择</font></div></td>
  </tr>
  <?
  while($r=$empire->fetch($sql))
  {
	//文件
	$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
	$filepath=$r[path]?$r[path].'/':$r[path];
	$file=$fspath['fileurl'].$filepath.$r[filename];
	//取得文件扩展名
	$filetype=GetFiletype($r[filename]);
	//播放器(media)
	if(strstr($mediaplayertype,",".$filetype.","))
	{
		$fileimg="<img src='../../data/type/mywmv.gif' border=0>";
	}
	else	//realplayer
	{
		  $fileimg="<img src='../../data/type/myrm.gif' border=0>";
	}
	$filesize=ChTheFilesize($r[filesize]);
	//返回地址
	$pic=$file;
	if($doing==1)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(1,'".$pic."');\">";
	}
	elseif($doing==2)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(2,'".$pic."');\">";
	}
	else
	{
		//编辑器选择
		if($tranfrom==1)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:EditorChangeFile('".$pic."');\">";
		}
		//特殊字段选择
		elseif($tranfrom==2)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:SFormIdChangeFile('$r[no]','$pic','$filesize','$filetype','$field');\">";
		}
		else
		{
			$button="<input type=button name=button value='插入' onclick=\"javascript:InsertFile('$file','$r[filename]','$r[fileid]','$filesize','$filetype','','rm');\">";
		}
	}
  ?>
  <tr> 
    <td bgcolor="#FFFFFF"> <div align="center">
	<input type=checkbox name=fileid[] value="<?=$r[fileid]?>"><br>
        <?=$r[fileid]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td>
              <?=$fileimg?>&nbsp;<?=$r[no]?>
            </td>
          </tr>
          <tr> 
            <td>
              <a href='<?=$pic?>' target=_blank><?=$r[filename]?></a>
              </td>
          </tr>
        </table>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$filesize?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$r[filetime]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <?=$button?>
      </div></td>
  </tr>
  <?
  }
  ?>
  <tr> 
    <td colspan="5" bgcolor="#FFFFFF">&nbsp;&nbsp;<?=$returnpage?>
        &nbsp;&nbsp;<input type="submit" name="Submit33" value="删除选中" onclick="document.dofile.enews.value='TDelFile_all';"><input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)">全选</td>
  </tr>
</table>
<?
}
//附件
else
{
?>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr>
    <td height="25">插入附件：</td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#698CC3">
  <tr> 
    <td width="7%"><div align="center"><font color="#FFFFFF">ID</font></div></td>
    <td width="43%"><div align="center"><font color="#FFFFFF">文件名</font></div></td>
    <td width="18%"><div align="center"><font color="#FFFFFF">大小</font></div></td>
    <td width="22%"><div align="center"><font color="#FFFFFF">上传时间</font></div></td>
    <td width="10%"><div align="center"><font color="#FFFFFF">选择</font></div></td>
  </tr>
  <?
  while($r=$empire->fetch($sql))
  {
	$filesize=ChTheFilesize($r[filesize]);
	//文件
	$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
	$filepath=$r[path]?$r[path].'/':$r[path];
	$path1=$fspath['fileurl'].$filepath.$r[filename];
	//取得文件类型
	$truefiletype=GetFiletype($r[filename]);
	$filetype=substr($truefiletype,1);
	//---------返回地址
	$pic=$path1;
	if($doing==1)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(1,'".$pic."');\">";
	}
	elseif($doing==2)
	{
		$returnstr=$pic;
		$button="<input type=button name=button value='选择' onclick=\"javascript:ChangeFile1(2,'".$pic."');\">";
	}
	else
	{
		//编辑器选择
		if($tranfrom==1)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:EditorChangeFile('".$pic."');\">";
		}
		//特殊字段选择
		elseif($tranfrom==2)
		{
			$button="<input type=button name=button value='选择' onclick=\"javascript:SFormIdChangeFile('$r[no]','$pic','$filesize','$truefiletype','$field');\">";
		}
		else
		{
			$button="<input type=button name=button value='插入' onclick=\"javascript:InsertFile('$pic','$r[filename]','$r[fileid]','$filesize','*.".$filetype."','','file');\">";
		}
	}
  ?>
  <tr> 
    <td bgcolor="#FFFFFF"> <div align="center">
	<input type=checkbox name=fileid[] value="<?=$r[fileid]?>"><br>
        <?=$r[fileid]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td>
              <?=$r[no]?>
            </td>
          </tr>
          <tr> 
            <td>
              <a href='<?=$path1?>' target=_blank><?=$r[filename]?></a>
              </td>
          </tr>
        </table>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$filesize?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center">
        <?=$r[filetime]?>
      </div></td>
    <td bgcolor="#FFFFFF"> <div align="center"> 
        <?=$button?>
      </div></td>
  </tr>
  <?
  }
  ?>
  <tr> 
    <td colspan="5" bgcolor="#FFFFFF">&nbsp;&nbsp;<?=$returnpage?>
        &nbsp;&nbsp;<input type="submit" name="Submit34" value="删除选中" onclick="document.dofile.enews.value='TDelFile_all';"><input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)">全选</td>
  </tr>
</table>
	  <?
}
?>
</form>
<center><input type="submit" name="Submit" value="关闭" onclick="window.close();"></center>
<IFRAME frameBorder="0" id="showclassnav" name="showclassnav" scrolling="no" src="../ShowClassNav.php?ecms=4&classid=<?=$searchclassid?>" style="HEIGHT:0;VISIBILITY:inherit;WIDTH:0;Z-INDEX:1"></IFRAME>
</body>
</html>
<?
db_close();
$empire=null;
?>
